      --Utils
      lfs     = require 'lfs'
      inspect = require 'scripts.utils.inspect'
      widget = require "widget"
      logger = require 'scripts.utils.logger'
      Vector = require 'scripts.utils.Vector'
      DisplayObjectUtils = require 'scripts.utils.DisplayObjectUtils'
      GeometricUtils = require 'scripts.utils.GeometricUtils'
      LuaUtils = require 'scripts.utils.LuaUtils'
      Sound = require 'scripts.utils.Sound'
      Font = require 'scripts.utils.Font'
      CBE = require 'CBEffects.Library'

      --Globals
      X, Y = display.viewableContentWidth,display.viewableContentHeight
      Y = Y-23 -- space for Ads
      halfX, halfY = X * 0.5, Y * 0.5
      require 'scripts.GameConstants'--Include several global variables
      playerLife = 3
      GameController = require 'scripts.controllers.GameController'
      GameWorld = require 'scripts.models.GameWorld'
         --Game Screen Models
         Circle = require 'scripts.models.Circle'
         Player = require 'scripts.models.Player'
      --Sounds
      playerYells = {}
      playerYells[1] = audio.loadSound("resources/sounds/playerYell1.wav")
      playerYells[2] = audio.loadSound("resources/sounds/playerYell2.wav")
      playerYells[3] = audio.loadSound("resources/sounds/playerYell3.wav")
      playerYells[4] = audio.loadSound("resources/sounds/playerYell4.wav")
      playerYells[5] = audio.loadSound("resources/sounds/playerYell5.wav")
      playerYells[6] = audio.loadSound("resources/sounds/playerYell6.wav")

      pissshs = {}
      pissshs[1] = audio.loadSound("resources/sounds/pisssh1.wav")
      pissshs[2] = audio.loadSound("resources/sounds/pisssh2.wav")
      pissshs[3] = audio.loadSound("resources/sounds/pisssh3.wav")
      pissshs[4] = audio.loadSound("resources/sounds/pisssh4.wav")

      playerWalk = {}
      playerWalk[1] = audio.loadSound("resources/sounds/walk1.wav")
      playerWalk[2] = audio.loadSound("resources/sounds/walk2.wav")

      playerRun = {}
      playerRun[1] = audio.loadSound("resources/sounds/run1.wav")
      playerRun[2] = audio.loadSound("resources/sounds/run2.wav")

      maskChange = {}
      maskChange[1] = audio.loadSound("resources/sounds/puff.wav")

      haunts = {}
      haunts[1] = audio.loadSound("resources/sounds/haunt01.wav")
      haunts[2] = audio.loadSound("resources/sounds/haunt02.wav")
      haunts[3] = audio.loadSound("resources/sounds/haunt03.wav")
      haunts[4] = audio.loadSound("resources/sounds/haunt08.wav")
      
      haunts2 = {}
      haunts2[1] = audio.loadSound("resources/sounds/haunt04.wav")
      haunts2[2] = audio.loadSound("resources/sounds/haunt05.wav")

      haunts3 = {}
      haunts3[1] = audio.loadSound("resources/sounds/haunt06.wav")
      haunts3[2] = audio.loadSound("resources/sounds/haunt07.wav")

      --music
      backgroundMusic = audio.loadStream("resources/sounds/bkgMusic.mp3")
      introMusic = audio.loadStream("resources/sounds/introMusic.mp3")
      creditsMusic = audio.loadStream("resources/sounds/creditsMusic.mp3")
--Cleaning logs
logger:clean()
logger:gameEvent('%s - %dx%d',system.getInfo("environment"),X,Y)

system.setIdleTimer(false) -- disable device sleep mode
display.setDefault('magTextureFilter', 'nearest')
display.setDefault('minTextureFilter', 'nearest')
display.setDefault('textureWrapX', 'repeat')
display.setDefault('textureWrapY', 'repeat')

function selectLevel()
   local storyboard = require "storyboard"
   storyboard.gotoScene("scripts.scenes.menu",{
      effect = "fade",time = 100
   })
end

function startLevel()
   local storyboard = require "storyboard"

   -- storyboard.gotoScene("scripts.scenes.GridTestScene", {effect = "fade",time = 100})
   storyboard.gotoScene("scripts.scenes.menu", {effect = "fade",time = 100})
end

local function myUnhandledErrorListener( event )
   local errorMessage = event.errorMessage .. event.stackTrace
   logger:debug(errorMessage)

   local errorBg = display.newRect(X*0.5,Y*0.5,X,Y)
   errorBg:setFillColor(1,1,1,0.5)
   local errorText = display.newText({
      text   = errorMessage,
      x      = X*0.51,
      y      = Y*0.51,
      align  = 'left',
      width  = X,
      height = Y,
      font   = native.systemFontBold,
      fontSize = 10
      })
   errorText:setTextColor(0,0,0,1)
   return false
end
Runtime:addEventListener("unhandledError", myUnhandledErrorListener)

-- local fps = require("scripts.utils.fps")
--       local performance = fps.PerformanceOutput.new();
--       performance.group.x, performance.group.y = X-20,Y-10
--       performance.group.alpha = 0.8; -- So it doesn't get in the way of the rest of the scene

startLevel()

--http://www.freesound.org/search/?q=game+music&f=&s=num_downloads+desc&advanced=0&g=1